<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class SwtIdentity extends Model
{
    use HasFactory, HasDateTimeFormatter;

    protected $table = 'swt_identity';

    protected $guarded = [];

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function getStartTimeAttribute($value)
    {
        return date('Y-m-d', strtotime($value));
    }

    public function getEndTimeAttribute($value)
    {
        $date = date('Y-m-d', strtotime($value));

        if($date == '2099-12-31') {
            return '长期';
        } else {
            return $date;
        }
    }
}
